﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Jemgine.Data
{
    public class SnapHelper
    {
        public static Vector2 Snap(Vector2 V, Vector2 GridSpacing)
        {
            V /= GridSpacing;
            V.X = (float)System.Math.Round(V.X);
            V.Y = (float)System.Math.Round(V.Y);
            V *= GridSpacing;
            return V;
        }

        public static float Snap(float f, float p)
        {
            f /= p;
            f = (float)System.Math.Round(f);
            f *= p;
            return f;
        }

        public static Vector2 Snap(Vector2 f, float p)
        {
            return new Vector2(Snap(f.X, p), Snap(f.Y, p));
        }
    }

    public interface Snapper
    {
        Vector2 SnapPosition(Vector2 V);
        float SnapScale(float s);
        float SnapRotation(float r);
    }

    public interface Translatable
    {
        Object PrepareToTranslate();
        void ApplyTranslation(Object Tag, Vector2 MouseDelta);
        void Snap(Snapper Snapper);
    }

    public interface Scalable
    {
        Object PrepareToScale();
        void ApplyScale(Object Tag, float Delta);
        void Snap(Snapper Snapper);
    }

    public interface Rotatable
    {
        Object PrepareToRotate();
        void ApplyRotation(Object Tag, float Rotation);
        void Snap(Snapper Snapper);
    }
}
